<?php
class Khong_dung_den extends CI_Controller{
    
    public function StatisBantien(){
        $jqxtheme = array(base_url() . 'library/jqwidgets/styles/jqx.darkblue.css');
        
        $jqueryui = array(base_url() . 'jscripts/jquery-ui/jquery-ui-1.8.21.min.js');
        
        $css_files = array(base_url() . 'jscripts/jqxGrid/styles/jqx.base.css');

        $js_files = array(
                base_url() . 'jscripts/jqxGrid/jqx-all.js'
        );

        $jqxgrid_init = $this->smarty->get_contents('backend/js/chart_bantien');
        $js_text = array($jqxgrid_init);
        
        //$this->smarty->assign('jqxtheme', $jqxtheme);
        $this->smarty->assign('jqueryui', $jqueryui);
        //$this->smarty->assign('css_files', $css_files);
        //$this->smarty->assign('js_files', $js_files);
        $this->smarty->assign('js_text', $js_text);
        
        $this->smarty->assign('title','Admin Panel - Xem doanh thu bắn tiền');
        $this->smarty->assign('heading','THỐNG KÊ : DOANH THU BẮN TIỀN');
        $this->smarty->view('backend/statistics/total', 'grid');
        $this->smarty->display('backend/admin');
        
        /*
        $user = $this->login_manager->get_user();
        $aParamAdminLog=array(
                        'username'   => $user[0]->name,
                        'customerID' => $user[0]->customerID,
                        'email'      => $user[0]->email,
                        'lastLogin'  => date("Y-m-d H:i:s"),
                        'logAction'  => "Thống kê : Tổng doanh thu",
                        'ip'         => $_SERVER['REMOTE_ADDR'],
                        'uID'        => $user[0]->uID
                        );
        $log = $this->db_user_model->insertUserAdminLog($aParamAdminLog);*/
    }
    
    
    public function data_json_googleChart(){
        if(IS_AJAX){
            
            $thongke = $this->db_statistics_model->getDataChart();
            $muathe = $this->db_statistics_model->getDataChart(array('task' => 'mua-the'));
            $bantien = $this->db_statistics_model->getDataChart(array('task' => 'ban-tien'));
            $thanhtoan = $this->db_statistics_model->getDataChart(array('task' => 'thanh-toan'));
            
            $table = array();
            $rows = array();
            $table['cols'] = array(
                                array('label' => 'Ngày', 'type' => 'string'),
                                array('label' => 'Mua thẻ', 'type' => 'string'),
                                array('label' => 'Bắn tiền', 'type' => 'number'),
                                array('label' => 'Thanh toán', 'type' => 'number'),
                            ); 
            
            foreach($bantien as $row){
                $temp = array();
                $temp[] = array('v' => convertDateTime($row->date));
                $temp[] = array('v' => (int)$row->totalamount);                  
                $rows[] = array('c' => $temp);
            }  
            
            $table['rows'] = $rows;
            
            $jsonTable = json_encode($table);
            
            echo $jsonTable;
        }
    }
    
    
    public function jqxChart(){
        $result = $this->db_statistics_model->getDataChart();
        $i = 1;
        for($month = 0; $month < 12; $month ++){
            foreach($result as $row){
                $temp = array();
                
                $temp[] = array('1/'.$i.'/2011',vndformat((int)$row->amount),vndformat((int)$row->cardprice));
                               
                foreach($temp as $rows){
                    echo implode(',', $rows)."\n\r";
                }
                $i++;
            }
        }
    }
    
    public function check(){

        $thu2 = isset($this->_arrParam['thu2']) ? $this->_arrParam['thu2'] : 1;
        $thu3 = isset($this->_arrParam['thu3']) ? $this->_arrParam['thu3'] : 2;
        $thu4 = isset($this->_arrParam['thu4']) ? $this->_arrParam['thu4'] : 3;
        $thu5 = isset($this->_arrParam['thu5']) ? $this->_arrParam['thu5'] : 4;
        $thu6 = isset($this->_arrParam['thu6']) ? $this->_arrParam['thu6'] : 5;
        $thu7 = isset($this->_arrParam['thu7']) ? $this->_arrParam['thu7'] : 6;
        $chunhat = isset($this->_arrParam['chunhat']) ? $this->_arrParam['chunhat'] :7;
        
        $datas = array(
                'cols' => array(
                            array('label' => 'Year', 'type' => 'string'),
                            array('label' => 'Doanh thu hàng ngày', 'type' => 'number'),
                            array('label' => 'Tài khoản nạp tiền theo cộng đồng', 'type' => 'string'),
                            array('label' => 'Đăng ký tài khoản hàng ngày', 'type' => 'number'),
                            array('label' => 'Tài khoản giao dịh của khách hàng', 'type' => 'string'),
                            array('label' => 'Tài khoản tổng hợp nạp tiền vào game', 'type' => 'number'),
                ),
                'rows' => array(
                            array('c' => array(array('v' => 'Thứ 2'), array('v' => (int)$thu2))),
                            array('c' => array(array('v' => 'Thứ 3'), array('v' => (int)$thu3))),
                            array('c' => array(array('v' => 'Thứ 4'), array('v' => (int)$thu4))),
                            array('c' => array(array('v' => 'Thứ 5'), array('v' => (int)$thu5))),
                            array('c' => array(array('v' => 'Thứ 6'), array('v' => (int)$thu6))),
                            array('c' => array(array('v' => 'Thứ 7'), array('v' => (int)$thu7))),
                            array('c' => array(array('v' => 'Chủ nhật'), array('v' => (int)$chunhat)))

                        )
                
        );
        
        echo json_encode($datas);
        
        //echo "<pre>";
          //  print_r($datas);
        //echo "</pre>";
        
    }
    public function check2(){
        
        $records = array(
                        array('1/1/2011','1271.87','2691.52'),
                        array('1/2/2011','1270.2','2681.25'),
                        array('1/3/2011','1271.87','2691.52'),
                        array('1/4/2011','1270.2','2681.25'),
                       
           );
           
        //$heading = implode(',', array_keys( array_pop($records) ) );
        
        //header("Content-type: application/octet-stream"); 
        //header("Content-Disposition: attachment; filename=\"yourfile.txt\"");
        
        //echo $heading."\n\r"; // HEADER IS BEING PLACED HERE
        
        foreach($records as $row){ // CONTENTS IS BEING PLACED HERE
            echo implode(',', $row)."\n\r";
        }
    }
    
    
    function thu(){
        /** ################################################################# */
        
        /** $check = date('d-m-Y H:i:s',strtotime("-7 day")); // 1 tuần
        echo $check; */
        
        // Tìm thứ trong ngày
        $result = $this->db_statistics_model->getDataChart();
        foreach($result as $date){ //$date->date => 2013-07-03 14:27:05
            $explode = explode(" ",$date->date); // Tách giờ
            $dates =  $explode[0];
            
            $exp = explode("-",$dates);
            //print_r($exp);
            
            // Chuyen thành mảng
            $nam = $exp[0];
            $thang = $exp[1];
            $ngay = $exp[2];
            
            // Tim thứ trong ngày
            $thu = SearchOrder($thang,$ngay,$nam);
            
            switch($thu){
                case "Monday" : $thus = "Thứ 2"; break;
                case "Tuesday" : $thus = "Thứ 3"; break;
                case "Wednesday" : $thus = "Thứ 4"; break;
                case "Thursday" : $thus = "Thứ 5"; break;
                case "Friday" : $thus = "Thứ 6"; break;
                case "Saturday" : $thus = "Thứ 7"; break;
                case "Sunday" : $thus = "Chủ nhật"; break;
                 
                default: $thus = "&nbsp; ('_')";break;
            }
            
            /** echo $thus." ".convertDateTime($dates)." ". vndformat($date->amount)." <br />"; */ #21CAD2
           
           echo $thus;
        }
    }
    
        
    public function hhh(){
        $today = date("j F Y");
        $time = strtotime(date("Y-m-d"));
        $muoi_ngay_truoc = strtotime("-10 day", $time);
        echo date("Y-m-d", $muoi_ngay_truoc);
        //echo " - ".$today." - ";
        $muoi_ngay_sau = strtotime("10 day", $time);
        //echo date("j F Y", $muoi_ngay_sau);

    }
}
?>